//
//  MyCollectionViewCell.m
//  FaceRecognition
//
//  Created by syun on 2018/1/22.
//  Copyright © 2018年 Sylar. All rights reserved.
//

#import "MyCollectionViewCell.h"

@implementation MyCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        float w = SCREENWIDTH/2 - 60;
        
        _photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(30, 15 , w, w)];
        _photoImageView.clipsToBounds = YES;
        _photoImageView.contentMode = UIViewContentModeScaleAspectFill;
        _photoImageView.image = [UIImage imageNamed:@"information_upload_photos_"];
        _photoImageView.userInteractionEnabled = YES;
        _photoImageView.layer.cornerRadius = 5;
        [self.contentView addSubview:_photoImageView];
        
        _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _selectBtn.frame = CGRectMake(0, w - 20, w, 20);
        [_selectBtn setBackgroundColor:DEFAULTCOLOR];
        
        [_selectBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_selectBtn setTitle:@"点击上传" forState:UIControlStateNormal];
        _selectBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_selectBtn addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
        [_photoImageView addSubview:_selectBtn];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(_photoImageView.frame) + 5, w, 15)];
        _nameLabel.textAlignment = NSTextAlignmentLeft;
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_nameLabel];
        
        _roleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(_nameLabel.frame) + 5, w, 15)];
        _roleLabel.textAlignment = NSTextAlignmentLeft;
        _roleLabel.textColor = [UIColor blackColor];
        _roleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_roleLabel];
        
        
    }
    
    return self;
}

- (void)setDataForCell:(ManagerPhotoModel *)model
{
    _selectBtn.tag = _indexRow + 50;

    if (model.fileurl.length > 0) {
        
        NSLog(@"model.name = %@",model.username);
        
        NSLog(@"model.fileurl = %@",model.fileurl);
        
       [_photoImageView sd_setImageWithURL:[NSURL URLWithString:model.fileurl] placeholderImage:[UIImage imageNamed:@"information_upload_photos_"]];
       [_selectBtn setTitle:@"更换图片" forState:UIControlStateNormal];
        model.havePhoto = YES;
        
    }else
    {
        _photoImageView.image = [UIImage imageNamed:@"information_upload_photos_"];
        [_selectBtn setTitle:@"点击上传" forState:UIControlStateNormal];
        model.havePhoto = NO;
    }
    
    
    
    _nameLabel.text = [NSString stringWithFormat:@"姓名：%@",model.username];
    
    //身份 1父亲 2 母亲 3爷爷 4 奶奶 5 姥爷 6姥姥 7 其它家长 8 姨妈
    
    NSString * typeStr;
    
    switch (model.type) {
        case 1:
            typeStr = @"父亲";
            break;
        case 2:
            typeStr = @"母亲";
            break;
        case 3:
            typeStr = @"爷爷";
            break;
        case 4:
            typeStr = @"奶奶";
            break;
        case 5:
            typeStr = @"姥爷";
            break;
        case 6:
            typeStr = @"姥姥";
            break;
        case 7:
            typeStr = @"其他家长";
            break;
        case 8:
            typeStr = @"姨妈";
            break;
        default:
            break;
    }
    
    _roleLabel.text = [NSString stringWithFormat:@"身份：%@",typeStr];
}

- (void)selectAction:(UIButton *)sender
{
    if ([_delegate respondsToSelector:@selector(photoChangeAtIndex:)]) {
        
        [_delegate photoChangeAtIndex:sender.tag];
    }
}


@end
